home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 7 May 1997
- // Author: cdt
- //
- // Procedure Name:
- // cameraMakeNode
- //
- // Description:
- // Creates extra camera nodes for the center of interest and up vector.
- //
- // Input Arguments:
- // count - Number of nodes to create.
- // camera - The camera transform name. Pass "" to use selection.
- //
- // Return Value:
- // None.
- //
-
- //
- // Procedure Name:
- // createLocator
- //
- proc string createLocator(string $name, float $position[])
- {
- string $targets[] = `spaceLocator -name $name -position 0 0 0`;
- string $target = $targets[0];
-
- // Set locator to have screen space icon
- string $targetShapes[] = `listRelatives $target`;
- string $targetShape = $targetShapes[0];
- setAttr ($targetShape+".visibility") false;
- setAttr ($target+".displayRotatePivot") true;
-
- move -absolute $position[0] $position[1] $position[2];
-
- return $target;
- }
-
- //
- // Procedure Name:
- // doLookAt
- //
- proc string doLookAt( string $camera )
- {
- string $shapes[] = `listRelatives -shapes $camera`;
-
- // Begin computing the center of interest in world space
- //
-
- float $coi[] = `camera -q -worldCenterOfInterest $camera`;
-
- //
- // End computing the center of interest in world space
-
- string $target = createLocator($camera+"_aim", $coi);
-
- string $lookAt = `createNode -name ($camera+"_group") "lookAt"`;
-
- // Fix for BUG 118280, the two node camera used to use "Scene Up"; but
- // this is problematic because if the camera is loaded into a scene with
- // a different up axis, the camera will have a different orientation than
- // the one it had been created for it.
- //
-
- // Orient the camera depending on users current up axis preferences.
- setAttr ".worldUpType" 3;
- if (`upAxis -q -axis` == "z") {
- setAttr ".worldUpVector" -type double3 0 0 1;
- }
- else {
- setAttr ".worldUpVector" -type double3 0 1 0;
- }
-
- setAttr ".aimVector" -type double3 0 0 -1;
-
- connectAttr ($target+".tx") ($lookAt+".target[0].targetTranslateX");
- connectAttr ($target+".ty") ($lookAt+".target[0].targetTranslateY");
- connectAttr ($target+".tz") ($lookAt+".target[0].targetTranslateZ");
- connectAttr ($target+".rp") ($lookAt+".target[0].targetRotatePivot");
- connectAttr ($target+".rpt") ($lookAt+".target[0].targetRotateTranslate");
- connectAttr ($target+".pm") ($lookAt+".target[0].targetParentMatrix");
-
- connectAttr ($camera+".pim") ($lookAt+".constraintParentInverseMatrix");
- connectAttr ($camera+".t") ($lookAt+".constraintTranslate");
- connectAttr ($camera+".rp") ($lookAt+".constraintRotatePivot");
- connectAttr ($camera+".rpt") ($lookAt+".constraintRotateTranslate");
-
- connectAttr ($lookAt+".constraintRotateX") ($camera+".rotateX");
- connectAttr ($lookAt+".constraintRotateY") ($camera+".rotateY");
- connectAttr ($lookAt+".constraintRotateZ") ($camera+".rotateZ");
- connectAttr ($lookAt+".distanceBetween") ($shapes[0]+".centerOfInterest");
-
- // Parent
- parent $camera $lookAt;
- parent $target $lookAt;
-
- return $lookAt;
- }
-
- //
- // Procedure Name:
- // doSelect
- //
- proc doSelect( string $camera )
- {
- string $view = getCameraNode( "view", $camera );
- string $up = getCameraNode( "up", $camera );
-
- string $selects = $camera;
- if ($up != "") $selects += " " + $up;
- if ($view != "") $selects += " " + $view;
-
- eval ("select "+$selects);
- }
-
- //
- // Procedure Name:
- // cameraMakeNode
- //
- global proc cameraMakeNode (int $count, string $camera)
- {
- if ($camera == "") {
- string $selected[] = `ls -selection`;
- $camera = $selected[0];
- }
-
- string $lookAt = getCameraNode( "lookAt", $camera );
- string $view = getCameraNode( "view", $camera );
- string $up = getCameraNode( "up", $camera );
-
- switch ($count) {
- case 1:
- if ($lookAt != "") ungroup $lookAt;
- if ($view != "") delete $view;
- if ($up != "") delete $up;
-
- break;
-
- case 2:
- // Does a look at already exist?
- if ($lookAt != "") {
- // Is there already an up?
- if ($up != "") delete $up;
- }
- else {
- doLookAt $camera;
- }
-
- break;
-
- case 3:
- // Does a look at not already exist?
- if ($lookAt == "") {
- $lookAt = doLookAt($camera);
- }
-
- // Begin computing the up in world space
- //
-
- float $upOrigin[] = `camera -q -worldUp $camera`;
- float $eye[] = `camera -q -position $camera`;
-
- $upOrigin[0] = $upOrigin[0] * 2.0 + $eye[0];
- $upOrigin[1] = $upOrigin[1] * 2.0 + $eye[1];
- $upOrigin[2] = $upOrigin[2] * 2.0 + $eye[2];
-
- //
- // End computing the up in world space
-
- string $up = createLocator($camera+"_up", $upOrigin);
- connectAttr ($up+".wm") ($lookAt+".worldUpMatrix");
-
- // Put the up node under the look at
- parent $up $lookAt;
-
- setAttr ($lookAt+".worldUpType") 1; // Use object
-
- break;
- }
-
- doSelect( $camera );
- }
-